#include<iostream>
#include"sqlite.hpp"
#include<cassert>
#include<vector>
int select_stu_balk(void* arg,int col_count,char** result,char** filed_name)
{
    std::vector<std::string>* as=(std::vector<std::string> *)arg;
    as->push_back(result[0]);
    return 0;
}
int main()
{
    SqliteHelper helper("./test.db");
    assert(helper.open());//确保打开
    const char* ct="create table if not exists student(sn int primary key,name varchar(32),age int);";
    assert(helper.exec(ct,nullptr,nullptr));//创建表
    //对表进行增删改
    // const char* str="insert into student values(1,'小明',18), (2, '小黑', 19), (3, '小红', 18);";
    // assert(helper.exec(str,nullptr,nullptr));
    // const char* str="update student set name='张晓明' where sn=1 ";
    // assert(helper.exec(str,nullptr,nullptr));
    // const char* str="delete from student where sn=3";
    // assert(helper.exec(str,nullptr,nullptr));
    //对表进行查询
    std::vector<std::string> arry;
    const char* str="select name from student;";
    assert(helper.exec(str,select_stu_balk,&arry));
    for(auto& e:arry)
    {
        std::cout <<e << std::endl;
    }
    //关闭数据库
    helper.close();
    return 0;
}